package sectorCrack;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;

import sectorCrack.bean.Dat;
import sectorCrack.bean.JobConfig;
import sectorCrack.manager.DataExtracter;
import sectorCrack.process.SectorQCProcessor;
import sectorCrack.utils.ByteFileCreator;
import sectorCrack.utils.PropertyManager;

public class MultipleFileJobRunner {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JobConfig jobConfig = null;
		try {
			jobConfig = PropertyManager.loadProperty(new FileInputStream("spikeFilter.properties"));
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
			jobConfig = new JobConfig();
		}

		File lrDir = new File(jobConfig.getInputPath());
		File[] lrFiles = lrDir.listFiles();

		for (File file : lrFiles) {
			try {
				if (file.getName().contains(".dat")) {
					System.out.println("working on " + file.getName());
					ArrayList<Dat> data = new DataExtracter(file).doExtract();
					// TextFileCreator.createFile(data, jobConfig.getOutputPath() + file.getName() + ".txt");
					new SectorQCProcessor(data, jobConfig).process();
					ByteFileCreator.createFile(data, jobConfig.getOutputPath() + file.getName());
					// TextFileCreator.createFile(data, "qcSector.txt");

				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		System.out.println("ok");
	}

}
